home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 43 / Amiga Format CD43 (1999)(Future Publishing)(GB)(Track 1 of 2)[!][issue 1999-09].iso / -serious- / archivers / xpk / xpk_source / xpkmaster / xpkmaster.h < prev    next >
C/C++ Source or Header  |  1999-06-14  |  11KB  |  280 lines

  1. #ifndef XPKMASTER_XPKMASTER_H
  2. #define XPKMASTER_XPKMASTER_H
  3.  
  4. /* Includeheader
  5.  
  6.     Name:        xpkmaster.h
  7.     Main:        xpkmaster
  8.     Versionstring:    $VER: xpkmaster.h 1.15 (13.09.1998)
  9.     Author:        SDI
  10.     Distribution:    Freeware
  11.     Description:    Master library global definitions and declarations
  12.             and prototypes
  13.  
  14.  1.0   05.10.96 : first real version
  15.  1.1   27.12.96 : removed library protos - call now via library interface,
  16.      allows patching
  17.  1.2   30.01.97 : change of cchecksum proto
  18.  1.3   31.01.97 : checksum changed again
  19.  1.4   01.03.97 : added new flags
  20.  1.5   08.03.97 : changed XpkBuffer a bit
  21.  1.6   31.03.97 : some little corrections
  22.  1.7   02.04.97 : removed obsolete stuff
  23.  1.8   12.04.97 : added DebugTagList
  24.  1.9   14.08.97 : fixed defines
  25.  1.10  20.12.97 : changed a lot in defines and structures
  26.  1.11  09.01.98 : added better key-fields to xbuf
  27.  1.12  24.01.98 : removed PP support --> done by xfdmaster now
  28.  1.13  21.02.98 : added code independence
  29.  1.14  25.06.98 : now uses SDI_compiler.h
  30.  1.15  13.09.98 : added seek, removed Powerpacker completely
  31. */
  32.  
  33. #ifdef SUPPORT_A4
  34.   #define A4SUPP    ,a4
  35.   #define A4SUPP2    ,xbuf->xb_regA4
  36.   #define A4PROTO    ,REG(a4, ULONG a4)
  37. #else
  38.   #define A4SUPP
  39.   #define A4SUPP2
  40.   #define A4PROTO
  41. #endif
  42.  
  43. #ifndef XPK_ALLINONE /* This allows some optimizations, when All.c is used */
  44.   #define XPK_ALLINONE
  45. #endif
  46.  
  47. #define SDI_TO_ANSI
  48. #include "SDI_ASM_STD_protos.h"
  49. #include "SDI_compiler.h"
  50.  
  51. #include <xpk/xpk.h>
  52. #include <xpk/xpksub.h>
  53.  
  54. typedef ASM(ULONG) (*regfunc) (REG(a0, struct Hook *),
  55.                    REG(a1, APTR), REG(a2, APTR) A4PROTO);
  56.  
  57. #define ROUNDLONG(x)        (((x)+3)&(~3))    /* round to next longword */
  58. #define DEFAULTCHUNKSIZE    0x8000
  59.  
  60. #ifndef Min
  61.   #define Min(a,b) ((a) < (b) ? (a) : (b))
  62.   #define max(a,b) ((a) > (b) ? (a) : (b))
  63. #endif
  64.  
  65. /* The structure used for I/O, special master library version */
  66. struct XpkMasterMsg {
  67.   ULONG  xmm_Type;        /* Read/Write/Alloc/Free/Abort        */
  68.   STRPTR xmm_Ptr;        /* The mem area to read from/write to    */
  69.   LONG   xmm_Size;        /* The size of the read/write        */
  70.   ULONG  xmm_IOError;        /* The IoErr() that occurred        */
  71.   ULONG  xmm_Reserved;        /* Reserved for future use        */
  72.   STRPTR xmm_Buf;        /* Specific to the internal hooks    */
  73.   LONG   xmm_Error;        /* The XPKERR that occurred        */
  74.   ULONG  xmm_BufLen;
  75.   ULONG  xmm_BufOfs;
  76.   ULONG  xmm_Len;
  77.   ULONG  xmm_Flags;
  78.   ULONG  xmm_FH;
  79.   ULONG  xmm_MemType;
  80.   STRPTR xmm_FileName;
  81. };
  82.  
  83. #define XIO_GETOUTBUF 1        /* flag for xmm_Flags - allocate buffer    */
  84.  
  85. /* These structures define the file format for compressed streams */
  86. struct XpkStreamHeader {
  87.   ULONG xsh_Pack;
  88.   ULONG xsh_CLen;
  89.   ULONG xsh_Type;
  90.   ULONG xsh_ULen;
  91.   UBYTE xsh_Initial[16];
  92.   UBYTE xsh_Flags;
  93.   UBYTE xsh_HChk;
  94.   UBYTE xsh_SubVrs;
  95.   UBYTE xsh_MasVrs;
  96. };
  97.  
  98. #define XPK_COOKIE    0x58504b46    /* 'XPKF' - ID for xsh_Pack */
  99. #define ROW_OF_MINUS    0x2d2d2d2d    /* '----' */
  100. #define XFD_COOKIE    0x58464444    /* 'XFDD' */
  101. #define USER_COOKIE    0x55534552    /* 'USER' */
  102.  
  103. #define XPKSTREAMF_LONGHEADERS  0x01    /* Use XpkLongLocHeaders    */
  104. #define XPKSTREAMF_PASSWORD     0x02    /* This file encoded        */
  105. #define XPKSTREAMF_EXTHEADER    0x04    /* Extended globhdr        */
  106.  
  107. struct XpkChunkHdrWord {
  108.   UBYTE xchw_Type;
  109.   UBYTE xchw_HChk;
  110.   UWORD xchw_CChk;
  111.   UWORD xchw_CLen;
  112.   UWORD xchw_ULen;
  113. };
  114.  
  115. struct XpkChunkHdrLong {
  116.   UBYTE xchl_Type;
  117.   UBYTE xchl_HChk;
  118.   UWORD xchl_CChk;
  119.   ULONG xchl_CLen;
  120.   ULONG xchl_ULen;
  121. };
  122.  
  123. typedef union {
  124.   struct XpkChunkHdrLong xch_Long;
  125.   struct XpkChunkHdrWord xch_Word;
  126. } XpkChunkHeader;
  127.  
  128. #define XPKCHUNK_RAW        0x00 /* raw copy of source */
  129. #define XPKCHUNK_PACKED        0x01 /* packed data */
  130. #define XPKCHUNK_END        0x0F /* empty end Chunk */
  131.  
  132. struct Headers {
  133.   struct XpkStreamHeader h_Glob;
  134.   XpkChunkHeader     h_Loc;
  135.   ULONG             h_LocSize;
  136. };
  137.  
  138. #define XPKMODE_UPUP    1
  139. #define XPKMODE_UPSTD   2
  140. #define XPKMODE_UPPP    3
  141. #define XPKMODE_UPXFD    4
  142. #define XPKMODE_PKSTD  20
  143.  
  144. #define AUTO_PASS_SIZE    50
  145.  
  146. struct SeekData {
  147.   ULONG sd_FilePos;
  148.   ULONG sd_ULen;
  149.   ULONG sd_CLen;
  150. };
  151.  
  152. #define SEEKENTRYNUM    10
  153.  
  154. struct SeekDataList {
  155.   struct SeekDataList *    sdl_Next;
  156.   ULONG            sdl_Used;
  157.   struct SeekData    sdl_Data[SEEKENTRYNUM];
  158. };
  159.  
  160. /* This is what XPK "handles" really point to */
  161. struct XpkBuffer {
  162.   struct XpkFib    xb_Fib;        /* file info about this file        */
  163.   UWORD   xb_PackingMode;    /* desired packing efficiency, 0..100   */
  164.   struct Headers xb_Headers;    /* global and local file header     */
  165.   ULONG   xb_Format;        /* type of file                */
  166.   LONG    xb_Result;        /* error code from last call        */
  167.   STRPTR  xb_ErrBuf;        /* Where user wants the error        */
  168.   STRPTR *xb_GetOutBuf;        /* Where user wants the out buf addr    */
  169.   ULONG  *xb_GetOutLen;        /* Where user wants the output len    */
  170.   ULONG  *xb_GetOutBufLen;    /* Where user wants the out buf len    */
  171.   ULONG   xb_Secs;        /* Start time, the seconds        */
  172.   ULONG   xb_Mics;        /* Start time, the micros        */
  173.   struct Hook * xb_RHook;    /* input data hook            */
  174.   struct Hook * xb_WHook;    /* output data hook            */
  175.   struct Hook * xb_ChunkHook;    /* Hook to call between chunks        */
  176.   STRPTR  xb_Password;        /* password for de/encoding        */
  177.   ULONG   xb_PasswordSize;    /* password buffer size for own password*/
  178.   ULONG   xb_PassKey32;        /* password key, 32 bit            */
  179.   UWORD   xb_PassKey16;        /* password key, 16 bit            */
  180.   WORD    xb_Priority;        /* task pri during packing        */
  181.   ULONG   xb_SubID;        /* currently active sub ID        */
  182.   ULONG   xb_ChunkSize;        /* Chunk size to use for packing    */
  183.   ULONG   xb_FirstChunk;    /* First chunk size - largest chunk    */
  184.   ULONG   xb_Flags;        /* private for xpkmaster        */
  185.   ULONG   xb_InLen;        /* Number of bytes to (un)pack        */
  186.   ULONG   xb_UCur;        /* Current Uncrunched size (next chunk)    */
  187.   ULONG   xb_CCur;        /* Current Crunched size (next chunk)    */
  188.   LONG      xb_InBufferPos;    /* buffer position for seek        */
  189.   STRPTR  xb_LastMsg;        /* The last progress message        */
  190.   struct xfdBufferInfo * xb_xfd;/* xfdBufferInfo            */
  191.   struct XpkInfo * xb_SubInfo;    /* Info of current open sub-lib        */
  192.   struct Library * xb_SubBase;    /* Currently open sub-library        */
  193.   struct XpkMasterMsg xb_RMsg;    /* Parameters for reading        */
  194.   struct XpkMasterMsg xb_WMsg;    /* Parameters for writing        */
  195.   struct XpkSubParams xb_PackParam;/* Parameters to (Un)PackChunk()    */
  196.   struct XpkProgress  xb_Prog;    /* Parameters to progress report    */
  197.   struct SeekDataList * xb_SeekDataList; /* this is used for seek    */
  198. #ifdef SUPPORT_A4
  199.   ULONG      xb_regA4;
  200. #endif
  201. };
  202.  
  203. /* Values for MasterFlags */
  204. #define XMF_PRIVFH    (1<< 0)    /* We opened the FH, so we close it.    */
  205. #define XMF_PACKING    (1<< 1)    /* This is a packing operation.        */
  206. #define XMF_PASSTHRU    (1<< 2)    /* Pass uncompressed data through    */
  207. #define XMF_GETOUTBUF    (1<< 3)    /* Get output buffer when size known    */
  208. #define XMF_NOCLOBBER    (1<< 4)    /* Don't overwrite            */
  209. #define XMF_EOF        (1<< 5)    /* End of file                */
  210. #define XMF_INITED    (1<< 6)    /* Sublib buffers have been allocted    */
  211. #define XMF_GLOBHDR    (1<< 7)    /* GlobHdr is already written        */
  212. #define XMF_LOSSYOK    (1<< 8)    /* Lossy compression permitted        */
  213. #define XMF_OWNTASKPRI    (1<< 9) /* Altered task pri, restore        */
  214. #define XMF_NOCRC    (1<<10)    /* Do not check the checksum on decomp    */
  215. #define XMF_NOPREFS    (1<<11) /* Are prefs allowed ?            */
  216. #define XMF_XFD        (1<<12) /* Is XFD unpacking allowed ?        */
  217. #define XMF_EXTERNALS    (1<<13) /* Is extern allowed ?            */
  218. #define XMF_AUTOPASSWD    (1<<14) /* Automatic password            */
  219. #define XMF_AUTOPRHOOK  (1<<15) /* Automatic Progress hook        */
  220. #define XMF_NOPACK    (1<<16) /* destination file equals source    */
  221. #define XMF_OWNPASSWORD (1<<17) /* free password buffer later !!!    */
  222. #define XMF_KEY16    (1<<18) /* got a 16 bit key (needed, as key may */
  223. #define XMF_KEY32    (1<<19) /* got a 32 bit key  be 0 - no check)   */
  224. #define XMF_SEEK    (1<<20)    /* we need to built seek buffers    */
  225.  
  226. #ifdef DEBUG
  227. void     DebugError(STRPTR, ...);            /* debug.c */
  228. void     DebugRunTime(STRPTR, ...);            /* debug.c */
  229. void    DebugTagList(STRPTR, struct TagItem *);        /* debug.c */
  230. #endif
  231.  
  232. extern struct DosLibrary       *DOSBase;        /* libinit.a */
  233. extern struct Hook        fhinhook;        /* hook_fh.c */
  234. extern struct Hook        fhouthook;        /* hook_fh.c */
  235. extern struct IntuitionBase    *IntuitionBase;        /* libinit.a */
  236. extern struct Hook        meminhook;        /* hook_mem.c */
  237. extern struct Hook        memouthook;        /* hook_mem.c */
  238. extern struct ExecBase         *SysBase;        /* libinit.a */
  239. extern struct UtilityBase      *UtilityBase;        /* libinit.a */
  240. extern struct Library           *XpkBase;        /* libinit.a */
  241.  
  242. XPK_ALLINONE LONG    addseek(struct XpkBuffer *);
  243. XPK_ALLINONE LONG    callprogress(struct XpkBuffer *);            /* progress.c */
  244. XPK_ALLINONE UWORD    cchecksum(ULONG *, ULONG);                /* checksum.c */
  245. XPK_ALLINONE void    closesub(struct XpkBuffer *);                /* sublibs.c */
  246. XPK_ALLINONE LONG    freebufs(struct XpkBuffer *);                /* xbuf.h */
  247. XPK_ALLINONE void    freeseek(struct XpkBuffer *);
  248. XPK_ALLINONE struct XpkPrefsSemaphore *    GetPrefsSem(void);            /* objects.c */
  249. XPK_ALLINONE void    getUClen(struct XpkBuffer *, LONG *, LONG *);
  250. XPK_ALLINONE UBYTE    hchecksum(STRPTR, ULONG);                /* checksum.c */
  251. XPK_ALLINONE APTR    hookread(struct XpkBuffer *, ULONG, APTR, LONG);    /* hook.c */
  252. XPK_ALLINONE APTR    hookwrite(struct XpkBuffer *, ULONG, APTR, LONG);    /* hook.c */
  253. XPK_ALLINONE ULONG    idfromname(STRPTR);                    /* sublibs.c */
  254. XPK_ALLINONE struct XpkBuffer *        initxbuf(void);                /* xbuf.h */
  255. XPK_ALLINONE struct Library *        opensub(struct XpkBuffer *, ULONG);    /* sublibs.c */
  256. XPK_ALLINONE LONG    parsebuftags(struct XpkBuffer*, struct TagItem*);    /* tags.c */
  257. XPK_ALLINONE LONG    parseerrortags(struct TagItem *, LONG);            /* tags.c */
  258. XPK_ALLINONE void    parsegettags(struct XpkBuffer *);            /* tags.c */
  259. XPK_ALLINONE void    percentages(struct XpkFib *);                /* fib.c */
  260. XPK_ALLINONE LONG    updatefib(struct XpkBuffer *);                /* fib.c */
  261. XPK_ALLINONE ASM(LONG)    xpkopen(REG(a0, struct XpkBuffer **),
  262.             REG(a1, struct TagItem *), REG(d2,ULONG) A4PROTO);    /* open.c */
  263.  
  264. ASM(LONG)  LIBXpkExamine(REG(a0, struct XpkFib *), REG(a1, struct TagItem *) A4PROTO);
  265. ASM(LONG)  LIBXpkPack(REG(a0, struct TagItem *) A4PROTO);
  266. ASM(LONG)  LIBXpkUnpack(REG(a0, struct TagItem *) A4PROTO);
  267. ASM(LONG)  LIBXpkOpen(REG(a0, struct XpkBuffer **), REG(a1, struct TagItem *) A4PROTO);
  268. ASM(LONG)  LIBXpkRead(REG(a0, struct XpkBuffer *), REG(a1, STRPTR), REG(d0, ULONG));
  269. ASM(LONG)  LIBXpkWrite(REG(a0, struct XpkBuffer *), REG(a1, STRPTR), REG(d0, ULONG));
  270. ASM(LONG)  LIBXpkSeek(REG(a0, struct XpkBuffer *), REG(d0, LONG), REG(d1, LONG));
  271. ASM(LONG)  LIBXpkClose(REG(a0, struct XpkBuffer *));
  272. ASM(LONG)  LIBXpkQuery(REG(a0, struct TagItem *));
  273. ASM(APTR)  LIBXpkAllocObject(REG(d0, ULONG), REG(a0, struct TagItem *));
  274. ASM(void)  LIBXpkFreeObject(REG(d0, ULONG), REG(a0, APTR));
  275. ASM(BOOL)  LIBXpkPrintFault(REG(d0, LONG), REG(a0, STRPTR));
  276. ASM(ULONG) LIBXpkFault(REG(d0, LONG), REG(a0, STRPTR), REG(a1, STRPTR), REG(d1, ULONG));
  277. ASM(LONG)  LIBXpkPassRequest(REG(a0, struct TagItem *));
  278.  
  279. #endif /* XPKMASTER_XPKMASTER_H */
  280.